from django.db import models
from django.contrib.auth.models import User

# Create your models here.

class ExtraReview(models.Model):
    """附加分审查表 - 对应picture表（证书图片审查）"""
    sort = models.CharField(max_length=255, blank=True, verbose_name='类别', db_comment='证书类别')
    name = models.CharField(max_length=25, blank=True, verbose_name='证书名', db_comment='证书名称')
    ranks = models.CharField(max_length=25, blank=True, verbose_name='级别', db_comment='证书级别')
    levels = models.CharField(max_length=25, blank=True, verbose_name='等级', db_comment='证书等级')
    picture = models.CharField(max_length=500, blank=True, null=True, verbose_name='证书图片', db_comment='证书图片URL')
    grade = models.IntegerField(null=True, blank=True, verbose_name='分数', db_comment='对应分数')
    
    # 审核状态
    first_efficient = models.BooleanField(default=False, verbose_name='学工办生效', db_comment='学工办审核状态')
    second_efficient = models.BooleanField(default=False, verbose_name='辅导员生效', db_comment='辅导员审核状态')
    third_efficient = models.BooleanField(default=False, verbose_name='班委生效', db_comment='班委审核状态')
    
    # 关联信息
    time = models.IntegerField(null=True, blank=True, verbose_name='年份', db_comment='年份')
    student = models.ForeignKey(
        User, 
        on_delete=models.CASCADE, 
        null=True,
        blank=True,
        related_name='extra_reviews',
        verbose_name='学生',
        db_comment='学生ID'
    )
    classes = models.CharField(max_length=25, blank=True, verbose_name='班级', db_comment='班级')
    auditor = models.CharField(max_length=255, blank=True, verbose_name='审查人员', db_comment='审查人员')
    
    created_at = models.DateTimeField(auto_now_add=True, null=True, blank=True, verbose_name='创建时间', db_comment='创建时间')
    updated_at = models.DateTimeField(auto_now=True, null=True, blank=True, verbose_name='更新时间', db_comment='更新时间')
    
    class Meta:
        db_table = 'zongce_extra_review'
        verbose_name = '附加分审查'
        verbose_name_plural = '附加分审查'
        ordering = ['-created_at']
        db_table_comment = '附加分审查表，存储学生证书附加分的审核信息'
    
    def __str__(self):
        return f"{self.student.username} - {self.name} - {self.ranks}"
